import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
    id: parameterSettingBack_Window
    width: 1770
    height: 1010


    property real button_Width: 180
    property real button_Height: 60
    property real buttonFontPixle: 20
    property int currentPage

    Rectangle{
        anchors.fill: parent
        gradient: Gradient{

            orientation: Gradient.Vertical
            GradientStop { position: 0.0 ; color: "#FFFFFF"}
            GradientStop { position: 0.5 ; color: "#1E90FF"}
            GradientStop { position: 1.0 ; color: "#FFFFFF"}
        }
    }

    Component.onCompleted: {
        currentPage = 1
        parameterLoader.source = "ConnectParameter_ParameterWindow.qml"
    }

    A_NumberKeyboard{
        id: settingsManagerKeyboard
    }

    Row{
        anchors.left: parameterSettingBack_Window.left
        anchors.leftMargin: 5
        anchors.top: parameterSettingBack_Window.top
        anchors.topMargin: 5
        spacing: 5

        A_Button{
            buttonWidth: button_Width
            buttonHeight: button_Height
            contentText_Data: qsTr("连接参数")
            isSelected: currentPage === 1

            onButtonClicked: {
                currentPage = 1
                parameterLoader.source = "ConnectParameter_ParameterWindow.qml"
            }

        }
        A_Button{
            buttonWidth: button_Width
            buttonHeight: button_Height
            contentText_Data: qsTr("设备参数")
            isSelected: currentPage === 2

            onButtonClicked: {
                currentPage = 2
                parameterLoader.source = "MechineParameter_ParameterWindow.qml"
            }

        }
        A_Button{
            buttonWidth: button_Width
            buttonHeight: button_Height
            contentText_Data: qsTr("伺服参数")
            isSelected: currentPage === 3

            onButtonClicked: {

                if(Cpp_PLC.Log_Flag)
                {
                    currentPage = 3
                    parameterLoader.source = "ServoParameter_ParameterWindow.qml"
                }
                else
                {
                    passwdManager.visible = true
                }
            }

        }
        A_Button{
            buttonWidth: button_Width
            buttonHeight: button_Height
            contentText_Data: qsTr("托料架参数")
            isSelected: currentPage === 4
            visible: Cpp_PLC.M_397

            onButtonClicked: {

                if(Cpp_PLC.Log_Flag)
                {
                    currentPage = 4
                    parameterLoader.source = "BracketParameter_ParameterWindow.qml"
                }
                else
                {
                    passwdManager.visible = true
                }
            }

        }
        A_Button{
            buttonWidth: button_Width
            buttonHeight: button_Height
            contentText_Data: qsTr("位置补偿")
            isSelected: currentPage === 5

            onButtonClicked: {

                if(Cpp_PLC.Log_Flag)
                {
                    currentPage = 5
                    parameterLoader.source = "LocationCompensation_ParameterWindow.qml"
                }
                else
                {
                    passwdManager.visible = true
                }
            }

        }
        A_Button{
            buttonWidth: 220
            buttonHeight: button_Height
            contentText_Data: qsTr("任意位置补偿")
            isSelected: currentPage === 6

            onButtonClicked: {

                if(Cpp_PLC.Log_Flag)
                {
                    currentPage = 6
                    parameterLoader.source = "AnyLocationCompensation_ParameterWindow.qml"
                }
                else
                {
                    passwdManager.visible = true
                }
            }

        }        

    }


    Loader{         // 参数设置加载
        id: parameterLoader
        anchors.top: parameterSettingBack_Window.top
        anchors.topMargin: 70
        anchors.horizontalCenter: parameterSettingBack_Window.horizontalCenter

        onSourceChanged: {
            console.log("当前参数设置界面为: " + source)
        }
    }


    Popup{      // 登录密码输入弹窗
        id: passwdManager
        anchors.centerIn: parent
        width: 1200
        height: 650
        closePolicy : Popup.NoAutoClose
        modal:  true
        dim: true

        background: Rectangle{
            radius: 10
            border.width: 1
            color: "white"

            Text{
                id: managerText
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 100
                font.pixelSize: Cpp_Language.CurrentLanguage === 1 ? 80 : Cpp_Language.CurrentLanguage === 2 ? 50 : Cpp_Language.CurrentLanguage === 3 ? 50 : 80
                color: "black"
                text: qsTr("请输入管理密码")
            }

            // Text{
            //     anchors.horizontalCenter: parent.horizontalCenter
            //     anchors.top: parent.top
            //     anchors.topMargin: 240
            //     font.pixelSize: Cpp_Language.CurrentLanguage === 1 ? 80 : Cpp_Language.CurrentLanguage === 2 ? 50 : Cpp_Language.CurrentLanguage === 3 ? 50 : 80
            //     color: "red"
            //     text: qsTr("默认为: 2222 ")
            // }

            A_NumberInput{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 240
                inputWidth: 300
                inputHeight: 50
                keyboard: settingsManagerKeyboard

                onEditingFinished: function(value)
                {
                    if(value === "2222")
                    {
                        Cpp_PLC.write_into_PLC_Coils(600,true)
                        passwdManager.close();
                    }
                    else
                    {
                        managerText.text = qsTr("密码错误,请重新输入")
                    }
                }
            }

            A_Button{
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 20
                anchors.horizontalCenter: parent.horizontalCenter
                contentText_Data: qsTr("关  闭")
                onButtonClicked: {
                    managerText.text = qsTr("请输入管理密码")
                    passwdManager.close();
                }
            }
        }


    }


}
